<!DOCTYPE html>
<!-- ng-app -->
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title>标记式注入</title>
    <script src="../../../js/plugins/angular/angular.min.js" type="text/javascript"></script>
</head>
<body>
    <div ng-controller="cont">
        <div class="show">{{text}}</div>
        <input type="button" id="btnShow" value="弹出" ng-click="onShow('我是一个弹出对话框')">
        <input type="button" id="btnWrite" value="显示" ng-click="onWrite('今天天气有点冷啊')">
    </div>

    <script>
        var cont = function ($scope,$show,$write) {
            $scope.onShow = function (msg) {
                $show.show(msg);
            }
            $scope.onWrite = function (msg) {
                $scope.text = $write.write(msg);
            }
        }

        cont.$inject = ['$scope','$show','$write'];
        angular.module('app',[])
            .controller('cont',cont)
            .factory('$show',['$window',function ($window) {
                return {
                    show:function (text) {
                        $window.alert(text);
                    }
                };
        }])
        .factory('$write',function () {
            return {
                write:function (text) {
                    return text;
                }
            };
        });

    </script>
</body>
</html>